<?php
/**
 * Accounts Controller Files for com_accounts Component
 *
 * @package    Joomla
 * @subpackage Accounts
 * @license		GNU/GPL
 */

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die();

/**
 * Accounts Controller Files
 *
 * @package    Joomla
 * @subpackage accounts
 */
class AccountsControllerFiles extends AccountsController
{
	/**
	 * constructor (registers additional tasks to methods)
	 * @return void
	 */
	function __construct()
	{
		parent::__construct();
	}

	/**
	 * display the edit form
	 * @return void
	 */

	 function show(){
	 	//$model = $this->getModel( 'files' );
	 	JRequest::setVar( 'view', 'files' );
		JRequest::setVar( 'layout', 'files' );
		parent::display( );
	 }

	/**
	 * load database records
	 * @return void
	 */

	 function load()
	 {
	 	$model = $this->getModel('files');
		if(!$model->load()){
			$msg = JText::_( 'WARNLOADFILE' );
			$msg .= $model->getError();
		}
		else{
			$msg = JText::_( 'LOADFILEOK' );
		}
		$link = 'index.php?option=com_accounts&controller=files&view=files&layout=files';
		$this->setRedirect( $link, $msg);
	 }


	/**
	 * remove file(s)
	 * @return void
	 */
	function remove()
	{
		$model = $this->getModel('files');
		if(!$model->delete()) {
			$msg = JText::_( 'WARNFILEDELETE' );
		} else {
			$msg = JText::_( 'FILEDELETEOK' );
		}

		$this->setRedirect( 'index.php?option=com_accounts&controller=files&view=files&layout=files', $msg );
	}

	/**
	 * cancel editing a record
	 * @return void
	 */
	function cancel()
	{
		$msg = JText::_( 'Operation Cancelled' );
		$this->setRedirect( 'index.php?option=com_accounts', $msg );
	}

	function doUpload(){
		$model = $this->getModel('files');
		if($model->upload()){
			$msg = JText::_( 'UPLOADFILEOK' );
		}
		else{
			//$msg = JText::_( 'Error with file upload! Sorry!');
			$msg = $model->getError();
		}
		$link = 'index.php?option=com_accounts&controller=files&view=files&layout=files';
		$this->setRedirect($link, $msg);
	}
}
?>
